/*
 * Транспонирование графа
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* {{{ autoarray */
struct vector {
	int *data;
	int n;
	int max;
};

void
vector_init(struct vector *v, int p)
{
	if (p < 0)
		p = 0;
	v->max = 1 << p;
	v->n = 0;
	v->data = calloc((size_t) v->max, sizeof *v->data);
}

int
vector_append(struct vector *v, int a)
{
	int *t;

	if (v->max == 0)
		vector_init(v, 0);

	if (v->n + 1 > v->max) {
		t = realloc(v->data, sizeof *t * (v->max *= 2));
		if (!t) {
			fprintf(stderr, "vector_append(): failed to allocate %d bytes\n", v->max);
			return 1;
		} else {
			v->data = t;
		}
	}

	v->data[v->n++] = a;

	return 0;
}

int
vector_sort(struct vector *v, int (*cmpf)(const void *, const void *))
{
	if (v->max > 0 && v->n > 1) {
		qsort(v->data, (size_t) v->n, sizeof *v->data, cmpf);
		return 0;
	} else {
		return 1;
	}
}

int
vector_cleanup(struct vector *v)
{
	if (v->max > 0) {
		v->max = v->n = 0;
		free(v->data);
		v->data = NULL;
		return 0;
	} else {
		return 1;
	}
}
/* }}} */

int
numcmp(const void *p1, const void *p2)
{
	return * (const int *) p1 - * (const int *) p2;
}

int
main(int argc, char **argv)
{
	struct vector *al;
	int n, i, m, j, v;

	scanf("%d", &n);
	al = calloc(n, sizeof *al);
	for (i = 0; i < n; i++) {
		scanf("%d", &m);
		for (j = 0; j < m; j++) {
			scanf("%d", &v);
			vector_append(al + v - 1, i);
		}
	}
	for (i = 0; i < n; i++)
		vector_sort(al + i, numcmp);

	for (i = 0; i < n; i++) {
		printf("%d ", al[i].n);
		for (j = 0; j < al[i].n; j++)
			printf("%d ", al[i].data[j] + 1);
		fputc('\n', stdout);
		vector_cleanup(al + i);
	}

	free(al);
	return 0;
}
